package com.example.controller;

import com.example.entity.Result;
import com.example.entity.User;
import com.example.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
public class LoginController {
 
    @Autowired
    private LoginService loginService;
 
    @PostMapping("/test/login")
    public Result<?> login(@RequestBody User user){
        return loginService.login(user);
    }

    @GetMapping("/test/loginout")
    public Result<?> loginout(){
        return loginService.logout();
    }
    @RequestMapping("/hello")
    @PreAuthorize("hasAuthority('user') or hasAuthority('admin')")
    public String hello(){
        return "hello";
    }

    @RequestMapping("/hello1")
    @PreAuthorize("hasAuthority('admin')")
    public String hello1(){
        return "hello";
    }
}
 